package com.foreknow.demo7;

/**
 * 主人类
 */
public class Master {

    public void cure(Pet pet) { //pet = Penguin对象
        //int a = (int)34.56;
        //Dog d = (Dog) pet; //如果将大类型(父类型)传递给小类型(子类型)=====引用类型的强制类型转换(向下造型)
        if(pet.getHealth()<60) {
           pet.toHospital();
        }
    }

//    public void cure(Penguin penguin) {
//        if(penguin.getHealth()<50) {
//            penguin.setHealth(60);
//            System.out.println("治疗方式2......");
//        }
//    }

    public static void main(String[] args) {
        Master master = new Master();
        //Pet pet = new Dog(); //父类的引用指向子类的对象    int a = 1;   a = 2;
        Dog dog = new Dog();
        dog.setHealth(20);
        master.cure(dog); //如果将小类型(子类型)传递给大类型(父类型)=====引用类型的自动类型转换(向上造型)
        Penguin p = new Penguin();
        p.setHealth(30);
        master.cure(p);


        //Pet p = new Pet(); // 抽象类是不能new的
        //master.cure(p); //报错

//        Dog dog = new Dog();
//        dog.setHealth(30);
//        master.cure(dog);
//        Penguin penguin = new Penguin();
//        penguin.setHealth(20);
//        master.cure(penguin);
    }
}
